package vn.aptech.leaveManagementSystem.view.admin;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
//import vn.aptech.leaveManagementSystem.business.dto.MyConstant;

import vn.aptech.leaveManagementSystem.business.dto.Department;
import vn.aptech.leaveManagementSystem.business.dto.Detail;
import vn.aptech.leaveManagementSystem.business.dto.Holiday;
import vn.aptech.leaveManagementSystem.business.dto.UserLoginInfo;
import vn.aptech.leaveManagementSystem.business.model.MyModel;
import vn.aptech.leaveManagementSystem.business.parse.MyParse;
import vn.aptech.leaveManagementSystem.dao.DBManager;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class AdminForm extends JFrame{
	JPanel pnlMain;
	private JTable tbEmp;
	private JTable tbDep;
	private JTable tbHol;
	private JTable tbConfig;
	private JTextField txtfLeavingID;
	private JTextField txtfLeavingStartDate;
	private JTextField txtfLeavingEndDate;
	private JTextField txtfLeavingContact;
	private DefaultTableModel modelEmp,modelHol,modelDep;
	private JButton btnEmpView;
	private JButton btnAddUser;
	private JButton btnEmpUpdate;
	private JButton btnEmpDelete;
	private JButton btnEmpSearch;
	private JTextField txtfLeavingBalance;
	private JTable tbLeavingHoliday;
	MyModel mymodel = new MyModel();
	ArrayList arrEmployee = null;
	private JButton btnHolInsert;
	private JButton btnHolUpdate;
	private JButton btnDelete;
	private AdminForm thisForm=this;
	private JButton btnDepInsert;
	private JButton btnDepUpdate;
	private JButton btnDepDelete;
	public AdminForm()
	{
		initGUI();
		initData();
		initAction();
	}
	
	private void initData() {
		updateDataTableHoliday();
		updateDataTableDepartment();
	}
	
	private void initAction() {
		btnHolInsert.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DemoInsertHoliday demoinsertholiday=new DemoInsertHoliday(thisForm);
				demoinsertholiday.setVisible(true);
				demoinsertholiday.setAlwaysOnTop(true);
				thisForm.setEnabled(false);
			}
		});
		
		btnHolUpdate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (tbHol.getSelectedRow() != -1) {
					Vector<Object> v = (Vector<Object>) modelHol.getDataVector().elementAt(tbHol.getSelectedRow());
					int idHol=(int) v.get(0);
					DemoUpdateHoliday demoupdate=new DemoUpdateHoliday(thisForm, idHol);
					demoupdate.setVisible(true);
					demoupdate.setAlwaysOnTop(true);
					thisForm.setEnabled(false);
				}
				else
				{
					JOptionPane.showMessageDialog(null, "You haven't selected any row in Holiday table!");
				}
			}
		});
		
		tbHol.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					if (tbHol.getSelectedRow() != -1) {
						Vector<Object> v = (Vector<Object>) modelHol.getDataVector().elementAt(tbHol.getSelectedRow());
						int idHol=(int) v.get(0);
						DemoUpdateHoliday demoupdate=new DemoUpdateHoliday(thisForm, idHol);
						demoupdate.setVisible(true);
						demoupdate.setAlwaysOnTop(true);
						thisForm.setEnabled(false);
					}
					else
					{
						JOptionPane.showMessageDialog(null, "You haven't selected any row in Holiday table!");
					}
				}
			}
		});
		
		btnDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (tbHol.getSelectedRow() != -1) {
					int choosen=JOptionPane.showOptionDialog(null, "Do you want to delete this holiday?", "Warning!",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
					if(choosen==JOptionPane.YES_OPTION)
					{
						Vector<Object> v = (Vector<Object>) modelHol.getDataVector().elementAt(tbHol.getSelectedRow());
						int idHol=(int) v.get(0);
						try {
							mymodel.holidays.deleteHoliday(idHol);
							JOptionPane.showMessageDialog(null, "Delete successful!");
						} catch (SQLException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						updateDataTableHoliday();
					}
				}
				else
				{
					JOptionPane.showMessageDialog(null, "You haven't selected any row in Holiday table!");
				}
			}
		});
		
		btnDepInsert.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DemoInsertDepartment demoinsertdepartment=new DemoInsertDepartment(thisForm);
				demoinsertdepartment.setVisible(true);
				demoinsertdepartment.setAlwaysOnTop(true);
				thisForm.setEnabled(false);
			}
		});
		
		btnDepUpdate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (tbDep.getSelectedRow() != -1) {
					Vector<Object> v = (Vector<Object>) modelDep.getDataVector().elementAt(tbDep.getSelectedRow());
					int idDep=(int) v.get(0);
					DemoUpdateDepartment demoupdate=new DemoUpdateDepartment(thisForm, idDep);
					demoupdate.setVisible(true);
					demoupdate.setAlwaysOnTop(true);
					thisForm.setEnabled(false);
				}
				else
				{
					JOptionPane.showMessageDialog(null, "You haven't selected any row in Department table!");
				}
			}
		});
		
		tbDep.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					if (tbDep.getSelectedRow() != -1) {
						Vector<Object> v = (Vector<Object>) modelDep.getDataVector().elementAt(tbDep.getSelectedRow());
						int idDep=(int) v.get(0);
						DemoUpdateDepartment demoupdate=new DemoUpdateDepartment(thisForm, idDep);
						demoupdate.setVisible(true);
						demoupdate.setAlwaysOnTop(true);
						thisForm.setEnabled(false);
					}
					else
					{
						JOptionPane.showMessageDialog(null, "You haven't selected any row in Department table!");
					}
				}
			}
		});
		
		btnDepDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (tbDep.getSelectedRow() != -1) {
					int choosen=JOptionPane.showOptionDialog(null, "Do you want to delete this Department?", "Warning!",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
					if(choosen==JOptionPane.YES_OPTION)
					{
						Vector<Object> v = (Vector<Object>) modelDep.getDataVector().elementAt(tbDep.getSelectedRow());
						int idDep=(int) v.get(0);
						try {
							mymodel.departments.deleteDepartment(idDep);
							JOptionPane.showMessageDialog(null, "Delete successful!");
						} catch (SQLException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						updateDataTableDepartment();
					}
				}
				else
				{
					JOptionPane.showMessageDialog(null, "You haven't selected any row in Department table!");
				}
			}
		});
	}
	
	private void initGUI() {
		try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        }
		
		pnlMain = new JPanel();
		
		getContentPane().add(pnlMain);
		setVisible(true);
		setTitle("Admin Form");
		setSize(906, 569);
		setDefaultCloseOperation(EXIT_ON_CLOSE);

	
		setLocationRelativeTo(null);
		getContentPane().setLayout(null);
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBorderPainted(false);
		menuBar.setBounds(0, 0, 634, 21);
		getContentPane().add(menuBar);
		JMenu mnGeneral = new JMenu("General");
		menuBar.add(mnGeneral);
		
		JMenu mnNew = new JMenu("New");
		mnNew.setIcon(new ImageIcon("icons/gif/16x16/Add.gif"));
		mnGeneral.add(mnNew);
		
		JMenuItem mnNewUser = new JMenuItem("New User");
		mnNewUser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				AddUser addUser = new AddUser();
				addUser.setVisible(true);
			}
		});
		mnNewUser.setIcon(new ImageIcon("icons/gif/16x16/People.gif"));
		mnNew.add(mnNewUser);
		
		JMenuItem mnNewPublicHoliday = new JMenuItem("New Public Holiday");
		mnNewPublicHoliday.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				PublicHoliday publicHoliday = new PublicHoliday();
				publicHoliday.setVisible(true);
			}
		});
		mnNewPublicHoliday.setIcon(new ImageIcon("icons/gif/16x16/List.gif"));
		mnNew.add(mnNewPublicHoliday);
		
		JMenuItem miChangePassword = new JMenuItem("Change Password");
		miChangePassword.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				new ChangeAdPassword();
			}
		});
		miChangePassword.setIcon(new ImageIcon("icons/gif/16x16/Modify.gif"));
		mnGeneral.add(miChangePassword);
		
		JMenuItem miLogOut = new JMenuItem("Logout");
		miLogOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				/*setVisible(false);
				DemoLgFr lg = new DemoLgFr();
				lg.setVisible(true);*/
			}
		});
		miLogOut.setIcon(new ImageIcon("icons/png/16x16/Logout.png"));
		mnGeneral.add(miLogOut);
		
		JMenuItem miExit = new JMenuItem("Exit");
		miExit.setIcon(new ImageIcon("icons/gif/16x16/Exit.gif"));
		mnGeneral.add(miExit);
		
		JMenu mnHelp = new JMenu("Help");
		menuBar.add(mnHelp);
		
		JTabbedPane tpMain = new JTabbedPane(JTabbedPane.TOP);
		tpMain.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null));
		tpMain.setBounds(81, 22, 813, 514);
		getContentPane().add(tpMain);
		
		JLayeredPane lpEmp = new JLayeredPane();
		tpMain.addTab("Employee Management", null, lpEmp, null);
		
		
		JPanel pnlListEmp = new JPanel();
		pnlListEmp.setBounds(0, 0, 810, 485);
		lpEmp.add(pnlListEmp);
		pnlListEmp.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		pnlListEmp.setLayout(null);
		
		tbEmp = new JTable();

		
		modelEmp = new DefaultTableModel();
		modelEmp.addColumn("ID");
		modelEmp.addColumn("FirstName");
		modelEmp.addColumn("LastName");
		modelEmp.addColumn("Gender");
		modelEmp.addColumn("Birthday");
		modelEmp.addColumn("Address");
		modelEmp.addColumn("Email");
		modelEmp.addColumn("Phone");
		modelEmp.addColumn("DepartmentID");
		modelEmp.addColumn("PositionID");
		modelEmp.addColumn("Join Date");
		modelEmp.addColumn("User Name");
		modelEmp.addColumn("Status Emp");

		try {
			//MyModel mymodel = new MyModel();
			ResultSet rs = mymodel.employees.getEmployeesListForAdmin(); // rs=rsEmployee
			while (rs.next()) {
				
				String[] strTemp=new String[13];
				strTemp[0]=new Integer(rs.getInt("IDEmp")).toString();
				strTemp[1]=rs.getString("FirstName");
				strTemp[2]=rs.getString("LastName");
				strTemp[3]= new Integer(rs.getInt("Gender")).toString();
				strTemp[4]=rs.getDate("Birthday").toString();
				strTemp[5]=rs.getString("Address");
				strTemp[6]=rs.getString("Email");
				strTemp[7]=rs.getString("Phone");
				strTemp[8]=new Integer(rs.getInt("DepartmentID")).toString();
				strTemp[9]=new Integer(rs.getInt("PositionID")).toString();
				strTemp[10]=rs.getDate("JoinDate").toString();
				strTemp[11]=rs.getString("UserName");															
				strTemp[12]=new Integer(rs.getInt("StatusEmp")).toString();
				modelEmp.addRow(strTemp);															

			}
			tbEmp.setModel(modelEmp);
		 
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	

		JScrollPane spEmp=new JScrollPane(tbEmp);
		spEmp.setBounds(10, 48, 789, 426);
		pnlListEmp.add(spEmp);
		
		JToolBar tlbarEmp = new JToolBar();
		tlbarEmp.setBounds(10, 11, 800, 32);
		pnlListEmp.add(tlbarEmp);
		tlbarEmp.setBorder(null);
		
		btnEmpView = new JButton("View");
		btnEmpView.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				/*setVisible(false);
				ViewUser viewUser = new ViewUser();
				viewUser.setVisible(true);*/
			}
		});
		btnEmpView.setIcon(new ImageIcon("icons/gif/16x16/View.gif"));
		tlbarEmp.add(btnEmpView);
		
		btnAddUser = new JButton("Add User");
		btnAddUser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				AddUser addUser = new AddUser();
				addUser.setVisible(true);
				//mymodel.employees.get
				/*String user = obj.get_user();
				String pos = obj.get_position();
				Detail obj = new Detail(user,pos);
				new AddUser(obj); //new AddUser(null,true); */
		       // adduser.setVisible(true);
			}
		});
		btnAddUser.setIcon(new ImageIcon("icons/gif/16x16/Add.gif"));
		tlbarEmp.add(btnAddUser);
		
		btnEmpUpdate = new JButton("Update");
		btnEmpUpdate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				UpdateUser updateUser = new UpdateUser();
				updateUser.setVisible(true);
			}
		});
		btnEmpUpdate.setIcon(new ImageIcon("icons/gif/16x16/Update.gif"));
		tlbarEmp.add(btnEmpUpdate);
		
		btnEmpDelete = new JButton("Delete");
		btnEmpDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				DeleteUser deleteUser = new DeleteUser();
				deleteUser.setVisible(true);
			}
		});
		btnEmpDelete.setIcon(new ImageIcon("icons/gif/16x16/Delete.gif"));
		tlbarEmp.add(btnEmpDelete);
		
		btnEmpSearch = new JButton("Search");
		btnEmpSearch.setIcon(new ImageIcon("icons/gif/16x16/Search.gif"));
		tlbarEmp.add(btnEmpSearch);
		
		JLayeredPane lpDep = new JLayeredPane();
		tpMain.addTab("Department Management", null, lpDep, null);
		
		JPanel pnlListDep = new JPanel();
		pnlListDep.setBounds(3, 2, 805, 475);
		lpDep.add(pnlListDep);
		pnlListDep.setLayout(null);
		
		JToolBar tlbarDep = new JToolBar();
		tlbarDep.setBounds(10, 11, 798, 32);
		pnlListDep.add(tlbarDep);
		
		//////////////////////////////////////////////////////////////////////////
		btnDepInsert = new JButton("Insert");
		btnDepInsert.setIcon(new ImageIcon("icons/gif/16x16/Add.gif"));
		tlbarDep.add(btnDepInsert);
		
		btnDepUpdate = new JButton("Update");
		btnDepUpdate.setIcon(new ImageIcon("icons/gif/16x16/Update.gif"));
		tlbarDep.add(btnDepUpdate);
		
		btnDepDelete = new JButton("Delete");
		btnDepDelete.setIcon(new ImageIcon("icons/gif/16x16/Delete.gif"));
		tlbarDep.add(btnDepDelete);
		//----------------------------------------------------------------------
		tbDep = new JTable();
		modelDep=new DefaultTableModel(){
			@Override
			public boolean isCellEditable(int row, int column) {
				return false;
			}
		};
		
		modelDep.addColumn("ID Department");
		modelDep.addColumn("Department Name");
		tbDep.setModel(modelDep);
		tbDep.getColumnModel().getColumn(0).setPreferredWidth(20);
		tbDep.getColumnModel().getColumn(1).setPreferredWidth(300);
		tbDep.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		JScrollPane spDep=new JScrollPane(tbDep);
		spDep.setBounds(16, 46, 788, 418);
		pnlListDep.add(spDep);
		//---------------------------------------------------------------------------
		
		JLayeredPane lpHol = new JLayeredPane();
		
		tpMain.addTab("Holiday Management", null, lpHol, null);
		
		JPanel pnlListHol = new JPanel();
		pnlListHol.setBounds(0, 0, 808, 475);
		lpHol.add(pnlListHol);
		pnlListHol.setLayout(null);
		
		JToolBar tlbarHol = new JToolBar();
		tlbarHol.setBounds(10, 11, 798, 33);
		pnlListHol.add(tlbarHol);
		
		btnHolInsert = new JButton("Insert");
		btnHolInsert.setIcon(new ImageIcon("icons/gif/16x16/Add.gif"));
		tlbarHol.add(btnHolInsert);
		
		btnHolUpdate = new JButton("Update");
		btnHolUpdate.setIcon(new ImageIcon("icons/gif/16x16/Update.gif"));
		tlbarHol.add(btnHolUpdate);
		
		btnDelete = new JButton("Delete");
		btnDelete.setIcon(new ImageIcon("icons/gif/16x16/Delete.gif"));
		tlbarHol.add(btnDelete);
		
		//-----------------------------------------------------------
		tbHol = new JTable();
		modelHol = new DefaultTableModel(){
			@Override
			public boolean isCellEditable(int row, int column) {
				return false;
			}
		};
		modelHol.addColumn("ID Hol.");
		modelHol.addColumn("Event Name");
		modelHol.addColumn("Start Date");
		modelHol.addColumn("End Date");
		tbHol.setModel(modelHol);
		tbHol.getColumnModel().getColumn(0).setPreferredWidth(20);
		tbHol.getColumnModel().getColumn(1).setPreferredWidth(50);
		tbHol.getColumnModel().getColumn(2).setPreferredWidth(30);
		tbHol.getColumnModel().getColumn(3).setPreferredWidth(30);
		JScrollPane spHol=new JScrollPane(tbHol);
		spHol.setBounds(10, 52, 798, 412);
		pnlListHol.add(spHol);
		tbHol.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		//-----------------------------------------------------------
		JLayeredPane lpConfig = new JLayeredPane();
		tpMain.addTab("Configuration Management", null, lpConfig, null);
		
		JPanel pnlConfig = new JPanel();
		pnlConfig.setBounds(0, 0, 808, 475);
		lpConfig.add(pnlConfig);
		pnlConfig.setLayout(null);
		
		JToolBar tlbarConfig = new JToolBar();
		tlbarConfig.setBounds(10, 11, 798, 29);
		pnlConfig.add(tlbarConfig);
		
		JButton btnConfigUpdate = new JButton("Update Parameter");
		btnConfigUpdate.setIcon(new ImageIcon("icons/gif/16x16/Update.gif"));
		tlbarConfig.add(btnConfigUpdate);
		
		tbConfig = new JTable();
		tbConfig.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null},
				{null, null, null},
				{null, null, null},
			},
			new String[] {
				"ID", "Description", "Parameter"
			}
		));
		tbConfig.getColumnModel().getColumn(1).setPreferredWidth(413);
		tbConfig.getColumnModel().getColumn(2).setPreferredWidth(134);
		JScrollPane spConfig=new JScrollPane(tbConfig);
		spConfig.setBounds(10, 51, 798, 413);
		//tbConfig.setBounds(10, 51, 798, 413);
		pnlConfig.add(spConfig);
		
		JLayeredPane lpLeaving = new JLayeredPane();
		tpMain.addTab("Leaving", null, lpLeaving, null);
		
		JPanel pnlLeaving = new JPanel();
		pnlLeaving.setBounds(10, 0, 792, 475);
		lpLeaving.add(pnlLeaving);
		pnlLeaving.setLayout(null);
		
		JToolBar toolBar = new JToolBar();
		toolBar.setBounds(10, 11, 798, 28);
		pnlLeaving.add(toolBar);
		
		JButton btnLeavingNewApp = new JButton("Create New Leaving Application");
		btnLeavingNewApp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				/*DemoCreateNewApplicationForPersonnel createAppForm=new DemoCreateNewApplicationForPersonnel(this, UserLoginInfo.getUserInfo().getIDEmp());
				createAppForm.setVisible(true);
				createAppForm.setAlwaysOnTop(true);
				this.setEnabled(false);*/
			}
		});
		btnLeavingNewApp.setIcon(new ImageIcon("icons/gif/16x16/Add.gif"));
		toolBar.add(btnLeavingNewApp);
		
		JButton btnLeavingWithdrawCurrentApp = new JButton("Withdraw Current Leaving Application");
		btnLeavingWithdrawCurrentApp.setIcon(new ImageIcon("icons/gif/16x16/Trackback.gif"));
		toolBar.add(btnLeavingWithdrawCurrentApp);
		
		JButton btnLeavingCancelCurrentApp = new JButton("Cancel Current Leaving");
		btnLeavingCancelCurrentApp.setIcon(new ImageIcon("icons/gif/16x16/Cancel.gif"));
		toolBar.add(btnLeavingCancelCurrentApp);
		
		JButton btnLeavingViewHistory = new JButton("View History");
		btnLeavingViewHistory.setIcon(new ImageIcon("icons/gif/16x16/History.gif"));
		toolBar.add(btnLeavingViewHistory);
		
		JPanel pnlLeavingCurrentApp = new JPanel();
		pnlLeavingCurrentApp.setBorder(new TitledBorder(null, "Lasted Leave Application", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		pnlLeavingCurrentApp.setBounds(121, 50, 535, 279);
		pnlLeaving.add(pnlLeavingCurrentApp);
		pnlLeavingCurrentApp.setLayout(null);
		
		JComboBox cbbLeavingStatus = new JComboBox();
		cbbLeavingStatus.setBounds(102, 240, 416, 20);
		pnlLeavingCurrentApp.add(cbbLeavingStatus);
		
		txtfLeavingContact = new JTextField();
		txtfLeavingContact.setBounds(102, 209, 416, 20);
		pnlLeavingCurrentApp.add(txtfLeavingContact);
		txtfLeavingContact.setColumns(10);
		
		JLabel lblLeavingContact = new JLabel("Contact:");
		lblLeavingContact.setBounds(21, 212, 46, 14);
		pnlLeavingCurrentApp.add(lblLeavingContact);
		
		JLabel lblLeavingStatus = new JLabel("Status:");
		lblLeavingStatus.setBounds(21, 243, 46, 14);
		pnlLeavingCurrentApp.add(lblLeavingStatus);
		
		JLabel lblLeavingReason = new JLabel("Reason:");
		lblLeavingReason.setBounds(21, 126, 46, 14);
		pnlLeavingCurrentApp.add(lblLeavingReason);
		
		JTextArea txtaLeavingReason = new JTextArea();
		txtaLeavingReason.setBounds(102, 121, 416, 79);
		pnlLeavingCurrentApp.add(txtaLeavingReason);
		
		JLabel lblLeavingEndDate = new JLabel("End date:");
		lblLeavingEndDate.setBounds(21, 93, 71, 14);
		pnlLeavingCurrentApp.add(lblLeavingEndDate);
		
		txtfLeavingEndDate = new JTextField();
		txtfLeavingEndDate.setBounds(102, 90, 416, 20);
		pnlLeavingCurrentApp.add(txtfLeavingEndDate);
		txtfLeavingEndDate.setColumns(10);
		
		txtfLeavingStartDate = new JTextField();
		txtfLeavingStartDate.setBounds(102, 60, 416, 20);
		pnlLeavingCurrentApp.add(txtfLeavingStartDate);
		txtfLeavingStartDate.setColumns(10);
		
		txtfLeavingID = new JTextField();
		txtfLeavingID.setBounds(102, 29, 416, 20);
		pnlLeavingCurrentApp.add(txtfLeavingID);
		txtfLeavingID.setColumns(10);
		
		JLabel lblLeavingID = new JLabel("ID:");
		lblLeavingID.setBounds(21, 32, 46, 14);
		pnlLeavingCurrentApp.add(lblLeavingID);
		
		JLabel lblLeavingStartDate = new JLabel("Start date:");
		lblLeavingStartDate.setBounds(21, 63, 71, 14);
		pnlLeavingCurrentApp.add(lblLeavingStartDate);
		
		JLabel lblLeavingBalance = new JLabel("Leave Balance:");
		lblLeavingBalance.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblLeavingBalance.setForeground(Color.BLUE);
		lblLeavingBalance.setBounds(131, 346, 81, 14);
		pnlLeaving.add(lblLeavingBalance);
		
		txtfLeavingBalance = new JTextField();
		txtfLeavingBalance.setFont(new Font("Tahoma", Font.PLAIN, 12));
		txtfLeavingBalance.setForeground(UIManager.getColor("Desktop.background"));
		txtfLeavingBalance.setBounds(227, 343, 204, 20);
		pnlLeaving.add(txtfLeavingBalance);
		txtfLeavingBalance.setColumns(10);
		
		tbLeavingHoliday = new JTable();
		tbLeavingHoliday.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
			},
			new String[] {
				"ID", "Event", "Start date", "End date"
			}
		));
		tbLeavingHoliday.getColumnModel().getColumn(0).setPreferredWidth(70);
		tbLeavingHoliday.getColumnModel().getColumn(1).setPreferredWidth(267);
		tbLeavingHoliday.getColumnModel().getColumn(2).setPreferredWidth(105);
		tbLeavingHoliday.getColumnModel().getColumn(3).setPreferredWidth(110);
		tbLeavingHoliday.setBounds(10, 63, 772, 56);
		JScrollPane spLeavingHoliday=new JScrollPane(tbLeavingHoliday);
		spLeavingHoliday.setBounds(10, 401, 772, 63);
		pnlLeaving.add(spLeavingHoliday);
		
		JLabel lblLeavingHoliday = new JLabel("Upcoming holiday");
		lblLeavingHoliday.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblLeavingHoliday.setForeground(Color.BLUE);
		lblLeavingHoliday.setBounds(10, 385, 98, 14);
		pnlLeaving.add(lblLeavingHoliday);
		
		//////////////////////////////////////////////////////////////////////////
		
		
		JLabel jlblBackground = new JLabel("");
		jlblBackground.setBounds(0, 23, 82, 512);
		getContentPane().add(jlblBackground);
		jlblBackground.setBorder(new LineBorder(new Color(0, 0, 0)));
		jlblBackground.setIcon(new ImageIcon("backgrounds/Background0.png"));
		
		JLabel lblWelcome = new JLabel("New label");
		lblWelcome.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		lblWelcome.setHorizontalAlignment(SwingConstants.RIGHT);
		lblWelcome.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblWelcome.setForeground(UIManager.getColor("ComboBox.selectionBackground"));
		lblWelcome.setBounds(637, 0, 257, 21);
		
		getContentPane().add(lblWelcome);
		String strWelcome="User: ";
		if (UserLoginInfo.getUserInfo().isGender())
			strWelcome=strWelcome+"Mr. ";
		else
			strWelcome=strWelcome+"Mrs. ";
		strWelcome=strWelcome + UserLoginInfo.getUserInfo().getFirstName()+" "+ UserLoginInfo.getUserInfo().getLastName();
		lblWelcome.setText(strWelcome);
		
	}
	
	public void RemoveAllRows(DefaultTableModel tablemodel) {
		int n = tablemodel.getRowCount();
		for (int i = n - 1; i >= 0; i--) {
			tablemodel.removeRow(i);
		}
	}

	public void updateDataTableHoliday()
	{
		try {
			ResultSet rs = mymodel.holidays.getHolidayList();
			RemoveAllRows(modelHol);
			while (rs.next()) {
				Holiday tempHol=MyParse.toHoliday(rs);
				Vector<Object> v=new Vector<Object>();
				v.add(new Integer(tempHol.getIDHoliday()));
				v.add(tempHol.getEvent());
				v.add(tempHol.getStartDate().toString());
				v.add(tempHol.getEndDate().toString());
				modelHol.insertRow(tbHol.getRowCount(), v);													
			}
			tbHol.setModel(modelHol);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public void updateDataTableDepartment()
	{
		try {
			ResultSet rs = mymodel.departments.getDepartmentList();
			RemoveAllRows(modelDep);
			while (rs.next()) {
				Department tempDep=MyParse.toDepartment(rs);
				Vector<Object> v=new Vector<Object>();
				v.add(new Integer(tempDep.getIDDepartment()));
				v.add(tempDep.getDepartmentName());
				modelDep.insertRow(tbDep.getRowCount(), v);													
			}
			tbDep.setModel(modelDep);
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
	}
	


}
